﻿package classes.bonus 
{   
	import flash.display.Sprite; 
	import flash.net.SharedObject;
	
	import classes.bag.BagRockMan;
	import classes.savedata.RockmanData;
	
	import com.mttang.event.JEvent;
	import com.mttang.event.CommonEvent;
	import classes.GameSetting; 
	
	/**
	 * 奖励类
	 * @author rock
	 */
	public class BonusRockman extends Sprite
	{  
		private var _sMyName:String;//玩完名字
		private var _nLevel:Number;//当前等级数 
		private var _nMoney:Number;//总钱数
		private var _nExp:Number;//总经验数
		private var _nRockNum:Number;//总显示岩石数 
		private var _nRockNumNow:Number = 0//当前岩石数 
		private var _nLevelIndex:Number = 0; 
		 
		
		/**
		 * 用法：
		 * 1、进入战斗界面和每过一关,执行init()
		 * 2、每当得到一个物品、钱、岩石数增加时,执行show(_obj:Object)
		 * 3、每当过关时,执行save();
		 */
		public function BonusRockman()
		{
			//init(); 
		}
		
		/**
		 * 初始化战斗界面的显示数据 
		 */
		public function init():void
		{  
			var sharedObj:Object=SharedObject.getLocal(GameSetting.saveSoData).data.dataRockman[GameSetting.index - 1];
			
			_sMyName =sharedObj.user.name;
			_nLevel = parseInt(sharedObj.user.level);
			_nExp = parseInt(sharedObj.user.exp);//即时交互
			_nMoney = parseInt(sharedObj.user.money); //即时交互
			_nRockNumNow = 0;//即时交互
			_nLevelIndex = sharedObj.user.level;
			_nRockNum = parseInt(GameSetting.manExpArr[_nLevelIndex]);
			
			setData();
		} 
		//在界面上显示数据
		private function setData():void
		{
		    rockManName.text = _sMyName;
			rockManLevel.text = String(_nLevel);
			rockManMoney.text = String(_nMoney);//即时交互
			rockManExp.text = String(_nExp); //即时交互
			rockManNumNow.text = String(_nRockNumNow);//即时交互
			rockManNum.text = "/"+_nRockNum;
		}
		 
		/**
		 * 
		 * @param	obj : money,exp,stoneNum 
		 */
		public function show(_obj:Object=null):void
		{  trace("显示新数据")
			if (_obj != null)
			{   
				_nExp+=_obj.exp;
				_nMoney += _obj.money;
				_nRockNumNow += _obj.stoneNum;
				setData();//显示新的数据 
			}	
		} 
		
		//过关后保存奖励物品与金钱
		public function save():void
		{  trace("保存")
			_nLevelIndex++;
			 
			var sharedObj:Object=SharedObject.getLocal(GameSetting.saveSoData).data.dataRockman[GameSetting.index - 1];
			 
			sharedObj.user.name = _sMyName; 
			sharedObj.user.level = _nLevelIndex;
			sharedObj.user.exp = _nExp; 
			sharedObj.user.money = _nMoney;   
		}
		
		//清理数据
		private function clearData():void
		{}
		
	}

}